package com.ctshk.sapp.season.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.AppReq;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.season.dto.FixedSeasonDetailsDTO;
import com.ctshk.rpc.season.dto.FixedSeasonProductPageDTO;
import com.ctshk.rpc.season.dto.StrategyInfoDateDTO;
import com.ctshk.rpc.season.req.SearchFixedProductReq;
import com.ctshk.rpc.season.req.SeasonFixedReplenishReq;
import com.ctshk.rpc.season.req.SeasonFixedSetReq;
import com.ctshk.rpc.season.req.SeasonProductStrategyQueryByDateReq;
import com.ctshk.rpc.season.service.ISeasonFixedProductPackageService;
import com.ctshk.rpc.season.service.ISeasonFixedProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 套票-固定套票单项产品打包表 前端控制器
 * </p>
 * @author 杨林
 * @since 2021-03-09
 */
@Api(value = "产品套票-固定套票单项产品", tags = "产品套票-固定套票单项产品")
@RestController
@RequestMapping("/season-fixed-product-package")
public class SeasonFixedProductPackageController extends BaseController {

    @DubboReference
    private ISeasonFixedProductPackageService seasonFixedProductPackageService;
    @DubboReference
    private ISeasonFixedProductService seasonFixedProductService;

    @ApiOperation(value = "固定套票产品设置", notes = "固定套票产品设置")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.UPDATE, operTitle = "固定套票产品设置", operDesc = "固定套票产品设置")
    @PostMapping("/update")
    public Result setFixedSeasonProduct(@RequestBody @Valid SeasonFixedSetReq seasonFixedSetReq) {
        TokenUser user = getCurrentUser(getRequest());
        //固定套票产品设置
        return seasonFixedProductPackageService.setFixedSeasonProduct(user, seasonFixedSetReq);
    }

    @ApiOperation(value = "预订中心-固定套票-产品分页查询列表", notes = "预订中心-固定套票-产品分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "预订中心-固定套票分页查询列表", operDesc = "预订中心-固定套票分页查询列表")
    @PostMapping("/reserveCentreList")
    public Result<PageResponse<FixedSeasonProductPageDTO>> reserveCentreList(@RequestBody SearchFixedProductReq searchFixedProductReq) {
        TokenUser user = getCurrentUser(getRequest());
        PageResponse<FixedSeasonProductPageDTO> response = seasonFixedProductPackageService.searchReserveCenterSeasonFixed(searchFixedProductReq, user);
        return Result.success(response);
    }

    @ApiOperation(value = "预订中心-固定套票-固定套票详情", notes = "预订中心-固定套票-固定套票详情")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "预订中心-固定套票详情", operDesc = "预订中心-固定套票详情")
    @PostMapping("/details")
    public Result<FixedSeasonDetailsDTO> details(@RequestBody SeasonFixedReplenishReq req, @ApiIgnore AppReq appReq) {
        TokenUser user = getCurrentUser(getRequest());
        //获取预订中心 固定套票 产品详情
        return seasonFixedProductPackageService.getFixedSeasonProductDetails(req.getProductId(), user.getId(), 1,appReq.getChannelId());
    }

    @ApiOperation(value = "预订中心-固定套票-套票详情可选日历选项", notes = "预订中心-固定套票-套票详情可选日历选项")
    @OperationLogAnnotation(operModul = OperationLogModel.SEASONFIXEDPRODUCT, operType = OperationLogType.QUERY, operTitle = "预订中心-套票详情可选日历选项", operDesc = "预订中心-套票详情可选日历选项")
    @PostMapping("/getOptionalCalendar")
    public Result<List<StrategyInfoDateDTO>> getOptionalCalendar(@RequestBody @Valid SeasonProductStrategyQueryByDateReq req) {
        TokenUser user = getCurrentUser(getRequest());
        //根据用户id  出发日期  结束日期 获取该 时间段内是否有 加幅信息
        List<StrategyInfoDateDTO> list = seasonFixedProductPackageService.getOptionalCalendar(req, user, 1);
        return Result.success(list);
    }

}
